cap program drop draw_graph_1x2
program define draw_graph_1x2, eclass
	args thebidder o additional_filename path min_partic graph_id
	if `min_partic' == .{
		di as error "Specify `min_partic' e.g. 3 in the firth augument"
	}
	local p  = 0
	if `thebidder' ~= 1 {
		cap drop thebidder
		*+di """RegfirmID`o'##########"
		qui gen thebidder = 1 if tsrank == `o'
	}
	qui count if thebidder == 1
	local partic = r(N)
	if `partic' >= `min_partic'{
		sort thebidder 
		local N = ftt_N1[1]
		local p = ftt_fr1[1]
		local t = mints1[1]
		local nmf = nm_firm[1]
		
		local fid = regionfirmID[1]
		local frg = region[1]
		local fad = ad_firm[1]
		local fli = no_license[1]
		preserve
			forvalues z = 1(1)2{
				foreach k in "s" "p" {
					local est`z'`k' = string(ftt_tau`z'`k'[1], "%6.3f")
					local se`z'`k' = string(ftt_se`z'`k'[1], "%6.3f")
					local ts`z'`k' = string(ftt_ts`z'`k'[1], "%6.3f")
					local drop`z'`k' = string(ftt_rank1obsdrop`z'`k'[1], "%6.0g")
					*di "####`drop`z'`k''####"
				}
			}
			cap drop theauction
			qui bys id: egen theauction = max( thebidder == 1 )
			qui keep if theauction == 1 & (rank1_p < . | rank1_s < .)
			*pause
			forvalues z = 1(1)1{				
				cap graph drop a`z'
				qui count if ldelta`z'p_s < . & ldelta`z's_s < . & ldelta`z's_s > 0 & tie`z's ~= 1
				local ns = r(N)
				qui count if ldelta`z'p_s < . & ldelta`z's_s < . & ldelta`z's_s > 0
				local nsT = r(N)
				cap noisily twoway ( ///
					scatter ldelta`z'p_s ldelta`z's_s if abs(ldelta`z's_s+.025) < .1250 ///
						& abs(ldelta`z'p_s-.025) < .1250 & ldelta`z's_s < 0, color(navy) xlabel(-.15(.05).1))( ///
					scatter ldelta`z'p_s ldelta`z's_s if abs(ldelta`z's_s+.025) < .1250 ///
						& abs(ldelta`z'p_s-.025) < .1250 & ldelta`z's_s > 0 , ///
							msymbol(T) color(navy)) ( ///
					scatter ldelta`z'p_s ldelta`z's_s if abs(ldelta`z's_s+.025) < .1250 ///
						& abs(ldelta`z'p_s-.025) < .1250 & ldelta`z's_s > 0 & ldelta`z'p_s > 0, ///
							msymbol(T) color(cyan))( ///
					scatter ldelta`z'p_s ldelta`z's_s if abs(ldelta`z's_s+.025) < .1250 & ldelta`z'p_s < 0 ///
						& abs(ldelta`z'p_s-.025) < .1250 & ldelta`z's_s < 0, color(cyan) ylabel(-.1(.05).15))( ///
					lpoly ldelta`z'p_s ldelta`z's_s if abs(ldelta`z's_s+.025) < .1250 ///
						& abs(ldelta`z'p_s-.025) < .1250 & ldelta`z's_s < 0, fc(none) deg(1) k(tri) ///
							clw(medthick) alw(medthick) clc(orange)	alp(shortdash) alc(gs5) ) ///
					if tie`z's ~= 1, name(a`z') legend(off) xline(0, lcolor(gs13)) yline(0, lcolor(gs13)) ///
						subtitle("est:`est`z's'(`se`z's')" "t = `ts`z's'" /*"N = `ns'(w/ tie:`nsT')"*/, ///
						place(ne) ring(0)) note("`drop`z's' dropped", size(small) place(sw) ring(0)) ///
						graphregion(color(white)) 
				if `z' == 1{
					di as result %-10.0g "`o') 1x2" %25s "`nmf'; " %37s "`fad'; N=" ///
					%6.0f "`partic'" "; Fl=" %3.2f `p' /// 
					"; est:" %4.2f `est1s' "(" %4.2f `se1s' "); t=" %5.2f `ts1s'
				}
				cap graph drop b`z'
				qui count if ldelta`z's_p < . & ldelta`z'p_p < . & ldelta`z'p_p < 0 & tie`z'p ~= 1
				local np = r(N)
				qui count if ldelta`z's_p < . & ldelta`z'p_p < . & ldelta`z'p_p < 0
				local npT = r(N)
				cap noisily twoway ( ///
					scatter ldelta`z's_p ldelta`z'p_p if abs(ldelta`z'p_p-.025) < .1250 ///
						& abs(ldelta`z's_p+.025) < .1250 & ldelta`z'p_p > 0, color(green) xlabel(-.1(.05).15))( ///
					scatter ldelta`z's_p ldelta`z'p_p if abs(ldelta`z'p_p-.025) < .1250 & ldelta`z's_p > 0 ///
						& abs(ldelta`z's_p+.025) < .1250 & ldelta`z'p_p > 0, color(lime) ylabel(-.15(.05).1))( ///
					scatter ldelta`z's_p ldelta`z'p_p if abs(ldelta`z'p_p-.025) < .1250 ///
						& abs(ldelta`z's_p+.025) < .1250 & ldelta`z'p_p < 0, color(green) ///
							msymbol(T) xlabel(-.1(.05).15))( ///
					scatter ldelta`z's_p ldelta`z'p_p if abs(ldelta`z'p_p-.025) < .1250 ///
						& ldelta`z's_p < 0 & abs(ldelta`z's_p+.025) < .1250 & ldelta`z'p_p < 0, ///
							msymbol(T) color(lime) ylabel(-.15(.05).1))( ///
					lpoly ldelta`z's_p ldelta`z'p_p if abs(ldelta`z'p_p-.025) < .1250 ///
						& abs(ldelta`z's_p+.025) < .1250 & ldelta`z'p_p > 0, fc(none) deg(1) k(tri) ///
							clw(medthick) alw(medthick) clc(orange)	alp(shortdash) alc(gs5) ) ///
					if tie`z's ~= 1, name(b`z') legend(off) xline(0, lcolor(gs13)) yline(0, lcolor(gs13)) ///
						subtitle("est:`est`z'p'(`se`z'p')" "t = `ts`z'p'" /*"N = `np'(w/ tie:`npT')"*/, ///
						place(ne) ring(0)) note("`drop`z'p' dropped", size(small) place(sw) ring(0)) ///
						graphregion(color(white))
				*cap hist dp`z' if abs(dp`z') < .1 & indep`z' < 0, xlabel(-.1(.05).1) bin(80) name(b`z')
			}			
			cap noisily graph combine a1 b1, cols(2) xsize(8) ysize(4) ///
				/*title("(`o')`nmf'; firmregionID:`fid'; # parti.: `partic'", size(small))*/ ///
				title("(`o') firmregionID:`fid'", size(small)) ///
				/*subtitle("#Lic.:`fli'; Ad.:`fad'", size(vsmall))*/ imargin(vsmall) scale(1) ///
				graphregion(color(white)) name(firm_`graph_id'_graph)
			cap /*noisily*/ graph export "`path'(`o'`additional_filename')`nmf'_`fad'_1x2.png", width(1450) replace
		restore
	}
end
	*************************************************************************

	
	